﻿var num = 0;
var page = 1;
var pagecount = "0";
 

$(document).ready(function () {
    var type = getUrlArgStr("type");
    var id = getUrlArgStr("id");

    shareload(page, id, type);
    $(window).bind("scroll", function () {
        //当滚动条滚动时
        var scollTop = $(this).scrollTop() + $(this).height();
        var scollH = $(document).height();

        if (scollH - scollTop < 100) {
            if (wait.isShow) { return; } //如果正在加载，则返回  
            page++;
            shareload(page, id, type);
        }
        return false;
    });

});

function shareload(pages, id, type) {
    if (!islogin()) { window.location.href = 'login.html'; return; }
    if (type == "Share") {
        //分享
        if (pagecount == "1") { return; }
        ajax.Sharequery("shared_id=" + id + "&day=" + getUrlArgStr("day") + "&page_index=" + pages, function (data) {
            if (data.code == 3) { Alert(data.msg); return; }
            if (data.item.pageCount == 0) { Alert('无记录！'); pagecount = "1"; return; }
            if (data.item.pageCount < pages) {
                if (pagecount == "0")
                    Alert('到底了！');
                pagecount = "1"; return;
            }
            if (data.item.itemCount > 0) {
                $(".topcententxt").html("查看人数 " + data.item.itemCount);
            }
            $(data.item.table).each(function () {
                var os = this.os == null ? "" : this.os;
                var browser = this.browser == null ? "" : this.browser;
                var address = this.address == null ? "" : this.address;

                $(".tab").append(" <tr><td>" + this.date + "</td><td>" + os + "</td><td>" + browser + "</td><td>" + address + "</td></tr>");
            });
        });
    }
    else {
        //广告
        if (pagecount == "1") { return; }
        ajax.Advertquery("advert_id=" + id + "&day=" + getUrlArgStr("day") + "&page_index=" + pages, function (data) {
            if (data.code == 3) { Alert(data.msg); return; }
            if (data.item.pageCount == 0) { Alert('无记录！'); return; }
            if (data.item.pageCount < pages) {
                if (pagecount == "0")
                    Alert('到底了！');
                pagecount = "1"; return;
            }
            if (data.item.itemCount > 0) {
                $(".topcententxt").html("查看人数 " + data.item.itemCount);
            }
            $(data.item.table).each(function () {

                var os = this.os == null ? "" : this.os;
                var browser = this.browser == null ? "" : this.browser;
                var address = this.address == null ? "" : this.address;

                $(".tab").append(" <tr><td>" + this.date + "</td><td>" + os + "</td><td>" + browser + "</td><td>" + address + "</td></tr>");
            });
        });

    }
}